// pages/login/login.js
const app = getApp()
import {
  login,
  getUserInfo
} from "../../api/user"
Page({
  /**
   * 页面的初始数据
   */
  data: {
    value: '',
    username: '',
    password: '',
  },

  //调用登录接口
  handleLogin() {
    //先获取输入框的内容
    login(this.data.username, this.data.password).then(res => {
      console.log(res)
      // debugger
      let cookie = res.cookies.join(";")
      if (cookie.includes('JSESSIONID')) {
        //登录成功的时候，把cookie放到storage里
        wx.setStorageSync('cookie', cookie)
      }
      if (res.data.code == 0) {
        app.globalData.isLogin = true;
        app.globalData.userInfo = res.data.data
        wx.switchTab({
          url: '/pages/my/my',

        }),
        wx.showToast({
          title: '登录成功',
        })
      } else {
        wx.showModal({
          showCancel: false,
          title: '登陆失败',
          content: res.data.msg
        })
      }

      //在每次发送请求的时候，都带上storage中的cookie 
      getUserInfo().then(res1 => {
        console.log(res1)
      })
    })

  } ,
  onShareAppMessage() {
    return {
      title: '放飞自我',
      imageUrl: "http://dpic.tiankong.com/ik/xm/QJ8181381674.jpg?x-oss-process=style/shows"
    }
  },
})

